package com.zou.study.spring.annotation;

import com.zou.study.spring.common.Person;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Date;

/**
 * @author _blank
 */
@Configuration
public class AnnotationConfigTests {

//    static class My implements ImportBeanDefinitionRegistrar {
//        @Override
//        public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
//
//            final RootBeanDefinition beanDefinition = new RootBeanDefinition();
//            beanDefinition.setBeanClass(Person.class);
//
//            registry.registerBeanDefinition("person", beanDefinition);
//
//        }
//    }

    @Bean
    public Person personBean() {
        Person person = new Person();

        person.setUserName("某某某");
        person.setGender("女");
        person.setEthnic("汉族");
        person.setBirthday(new Date(965123490000L));
        person.setAddress("省级行政区名称-区县级行政区名称-具体住宿地址");
        person.setCardNumber("110102YYYYMMDD888X");

        person.setIssuingAuthority("区县级公安局名称");
        person.setValidPeriod(new String[]{"20YY.MM.DD", "YYYY.MM.DD/长期"});

        return person;
    }

    public static void main(String[] args) {

        final String[] basePackages = {"com.zou.study.spring.annotation"};

        try (final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(basePackages)) {
            Person person = ctx.getBean(Person.class);
            System.out.println("\n" + person + "\n");
        }

    }

}
